#ifndef _COMPAT_EVENTS_KQUEUE_H_
#define _COMPAT_EVENTS_KQUEUE_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <crt_util.h>
#include "compat_event_util.h"

#if (TARGET_OS == OS_MACH || TARGET_OS == OS_UNIX)

typedef struct kqueue_op_s kqueue_op_t;
typedef struct kevent_s kevent_t;

struct kevent_s {
    uint32_t ctl;
	evoper_t* oper;
	evoper_queue queue;
	evevent event;
};

typedef int (*kqueue_fn)(void);
typedef int (*kevent_fn)(int, const struct kevent*, int, struct kevent*, int, const struct timespec*);

struct kqueue_op_s {
    int kqfd;
    int size;
    kqueue_fn sys_kqueue;
    kevent_fn sys_kevent;
    struct kevent* poll;
    struct kevent* change;
    struct kevent notify_kev;
    ev_op ev;
	
    _mutex_t lock;
	evloop_queue_t queue;
};

int kqueue_evop_t(evsysop_t* op);
int kevent_set_oper(kevent_t* ptr, evoper_t* oper);

#endif

#ifdef __cplusplus
}
#endif

#endif
